using FreeSql.DataAnnotations;

namespace SumerCoreDevOps.Domain.Entities;

/// <summary>
/// 构建产物
/// </summary>
[Table(Name = "build_artifacts")]
[Index("idx_task_id", nameof(TaskId), false)]
[Index("idx_build_history_id", nameof(BuildHistoryId), false)]
[Index("idx_node_id", nameof(NodeId), false)]
public class BuildArtifact
{
    /// <summary>
    /// 主键
    /// </summary>
    [Column(IsIdentity = true, IsPrimary = true)]
    public long Id { get; set; }

    /// <summary>
    /// 关联的任务 ID
    /// </summary>
    [Column(IsNullable = false)]
    public long TaskId { get; set; }

    /// <summary>
    /// 关联的构建历史 ID
    /// </summary>
    [Column(IsNullable = true)]
    public long? BuildHistoryId { get; set; }

    /// <summary>
    /// 产物所在的执行节点 ID
    /// </summary>
    [Column(IsNullable = false)]
    public long NodeId { get; set; }

    /// <summary>
    /// 产物名称
    /// </summary>
    [Column(StringLength = 255, IsNullable = false)]
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 产物类型（例如：zip, tar.gz, jar, dll, exe等）
    /// </summary>
    [Column(StringLength = 50, IsNullable = false)]
    public string Type { get; set; } = string.Empty;

    /// <summary>
    /// 文件大小（字节）
    /// </summary>
    [Column(IsNullable = false)]
    public long FileSize { get; set; }

    /// <summary>
    /// 存储路径（相对路径或绝对路径）
    /// </summary>
    [Column(StringLength = 500, IsNullable = false)]
    public string FilePath { get; set; } = string.Empty;

    /// <summary>
    /// MD5 哈希值（用于文件完整性验证）
    /// </summary>
    [Column(StringLength = 32, IsNullable = true)]
    public string? Md5Hash { get; set; }

    /// <summary>
    /// 描述
    /// </summary>
    [Column(StringLength = 500, IsNullable = true)]
    public string? Description { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    [Column(IsNullable = false)]
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    /// <summary>
    /// 过期时间（可选，用于自动清理旧产物）
    /// </summary>
    [Column(IsNullable = true)]
    public DateTime? ExpiresAt { get; set; }

    /// <summary>
    /// 是否已删除
    /// </summary>
    [Column(IsNullable = false)]
    public bool IsDeleted { get; set; } = false;

    /// <summary>
    /// 下载次数
    /// </summary>
    [Column(IsNullable = false)]
    public int DownloadCount { get; set; } = 0;
}
